package bank;

import java.util.Arrays;

public class _41FirstMissingPositive {
    public static int firstMissingPositive(int[] nums) {
        int res = 1;
        Arrays.sort(nums);
        if (nums[nums.length-1] <= 0){
            return 1;
        }
        for (int i = 0;i < nums.length;i++){
            if (nums[i] <= 0){
                continue;
            }
            if (i > 0 && nums[i] == nums[i-1]){
                continue;
            }
            if (nums[i] != res++){
                return res - 1;
            }
        }
        return nums[nums.length-1] + 1;
    }
}
